<?php
class penjualan extends CI_Model {

	function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }

    function insert($data){
        $this->db->insert('penjualan',$data);
    }
	
	function insertagihan($data){
        $this->db->insert('tagihan',$data);
    }

    function update($id,$data){
	
	
        $this->db->where('no_penjualan', $id);
        $this->db->update('penjualan', $data);
    }
	
	function updatepesanan($id,$data){
	
	
        $this->db->where('id_pesanan', $id);
        $this->db->update('pesnan', $data);
    }

    function delete($data){
        $this->db->where('no_penjualan', $data);
        $this->db->delete(penjualan);
    }

    function get_by_id($id){
        $query=$this->db->query("select * from penjualan where no_penjualan=".$id."");
        
        return $query;
    }
	
	//get maks penjualan
	
	function maksid(){
        $query=$this->db->query("select max(id_penjualan) as maksid from penjualan ");
        
        return $query;
    }
	
	
	function getPropertiesPenjualan($no_pengiriman){
	
	$query=$this->db->query("select *,pengiriman.status as status_pengiriman,pengiriman.tanggal as tanggal_pengiriman,konsumen.nama as nama_konsumen,konsumen.alamat as alamat_konsumen, karyawan.nama as nama_karyawan, barang.nama as nama_barang
       from pengiriman,pesanan,konsumen,karyawan,barang
	   where pengiriman.nomer_pesanan=pesanan.nomer_pesanan
		AND pengiriman.karyawan=karyawan.id_karyawan
		AND pesanan.no_konsumen=konsumen.id_konsumen
		AND pesanan.id_barang=barang.id_barang
		AND pengiriman.no_pengiriman='".$no_pengiriman."'");
        
        return $query;
	
	}
	
	function getPropertiesPenjualanAll(){
	
	$query=$this->db->query("select *,pengiriman.status as status_pengiriman,pengiriman.tanggal as tanggal_pengiriman,konsumen.nama as nama_konsumen,konsumen.alamat as alamat_konsumen, karyawan.nama as nama_karyawan, barang.nama as nama_barang
       from pengiriman,pesanan,konsumen,karyawan,barang
	   where pengiriman.nomer_pesanan=pesanan.nomer_pesanan
		AND pengiriman.karyawan=karyawan.id_karyawan
		AND pesanan.no_konsumen=konsumen.id_konsumen
		AND pesanan.id_barang=barang.id_barang ");
        
        return $query;
	
	}
	

    function get_all(){
	$this->db->select('*');
        $this->db->from('penjualan');
	
		  
        $query = $this->db->get();
        return $query->result_array();
    }
	
	

    function get_list(){
        $this->db->select('nama');
        $this->db->from('penjualan');
        $query = $this->db->get();
        return $query->result_array();
    }

    function get_by_nama($nama){
        $this->db->select('no_penjualan');
        $this->db->from('penjualan');
        $this->db->where('nama',$nama);
        $query = $this->db->get();
        return $query;
    }

   
}
